package com.muqi.app.qlearn.student.ui;

import java.io.Serializable;
import com.muqi.app.project.contants.MContants;
import com.muqi.app.qlearn.adapter.ChildAdapter;
import com.muqi.app.qlearn.adapter.ChildAdapter.onBecomeVip;
import com.muqi.app.qlearn.student.BaseStudentActivity;
import com.muqi.app.qlearn.student.R;
import com.muqi.app.user.db.ChildBean;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;

public class SelectChildActivity extends BaseStudentActivity implements
		OnItemClickListener, onBecomeVip {
	private GridView gv_child;
	private ChildAdapter adapter;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_select_child);

	}

	@Override
	protected void onInit() {
		super.onInit();
		gv_child = (GridView) findViewById(R.id.gv_user);
		gv_child.setOnItemClickListener(this);
		adapter=new ChildAdapter(mContext, myChildren);
		adapter.setBecomeVip(this);
		gv_child.setAdapter(adapter);

	}

	@Override
	protected void onData() {

		super.onData();
	}

	@Override
	protected void onChoiceChildResult(ChildBean myChild) {
		// TODO Auto-generated method stub

	}

	@Override
	public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
		ChildBean child = myChildren.get(arg2);
		mSpUtil.setCurrentChildId(child.child_id);
		mSpUtil.setChildClassId(child.class_id);
		mSpUtil.setChildGradeId(child.grade_id);
		mSpUtil.setChildSchoolId(child.school_id);
		mSpUtil.setChildName(child.name);
		mSpUtil.setClassName(child.class_name);
		mSpUtil.setSchoolName(child.school_name);
		mSpUtil.setCurrentIm(child.im_user_id);
		mSpUtil.setCurrentAva(child.avatar_02);
		currentChildName = child.name;

		onChoiceChildResult(child);
		Intent intent = new Intent();
		intent.setAction(MContants.CHANGE_CURRENT_CHILD_ACTION);
		intent.putExtra(MContants.CHANGE_CURRENT_CHILD_DATAS,
				(Serializable) child);
		sendBroadcast(intent);
		finish();

	}

	@Override
	public void becomeVip(String studentId) {
		Intent intent = new Intent(mContext, BecomeMemberActivity.class);
		intent.putExtra("student_id", studentId);
		Log.e("===", studentId);
		startActivity(intent);
		finish();

	}

}
